# -*- coding: utf-8 -*-
#输入 输出
# a = int(input())
# b = int(input())
# c = input()
# print(c)
# print(a+b)

#变量类型
a = 10
b = "huangxin"
floa = 100.0
#多个变量同时赋值
c=d=e=1
h,j,k = 1,2,"huangwei"
print(a,b)
print(floa,a,b,c,d,e,h,j,k,)

#字符串
len(k)
s = k[:4] #左闭右开
print(s)
print(k[::-1])#字符串反转


#运算符
a1 = 10
b1 = 2
print(a1**b1)#幂运算
print(a1//b1) #整除

#逻辑运算
# and or not
if a and b:
    print("true")

#成员运算符
x =1
item = [1,2,3,4]#不一定列表  元祖 字符串 都可以
if x in item :
    print("x in item")

if x not in item :
    print("x not  in item")



#标准数据类型
"""
1.number
2.string
3.list a = {1,2,3}
4.tuple (1,2,3)
5.dict{"lwq":25}

"""
#字符串
varl = "runoob"
varl[0]
varl[1:4]
#字符串运算
a = "hello"
b = "python"
print(a+b)
print(a*2)
c = 'e'
if c in a :
    print("true")
else :
    print(False)

#字符串内建函数
"""
capitalize() 将字符串的第一个字母大写
center(width,fillchar) :返回一个指定宽度的width的字符串 fillchar 为填充的字符
decode,encode;字节流
isalnum() 如果字符串至少已有一个字符且所有字符都是字母或数字 返回true 否则返回 false
isalpha() 判断字符串 如果全是字母则返回true
isdigit() 判断字符串 如果全是数字 返回true
len() 返回字符串长度
"""
varl.center(10,'q')
#切片
my_str = "asfasfasf"
print(my_str[-3:])
print(my_str[4:10])

my_str = my_str[::-1]
print(my_str)

a = 10
b = 20
a,b = b,a
print(a,b)



#列表 和 元组(不可重新赋值)
name_list = ["huangxin","lufei",18]
t = ("name1","name2")

print(name_list)
print(t)
name_list.append("巧了")
name_list.insert(0,"娜美")
print(name_list)
del name_list[2]
name_list.remove("娜美")
print(name_list)

name_list.pop(2)
print(name_list)

print(name_list.pop(0))

#两种remove 直接remove是没有返回值的  pop是有返回值的

name_list[0] = "hh"
print(name_list)

#操作符

len(name_list)
a = [1,2,3]
b = [4,5,6]
a.extend(b)
print(a)
print(a*2)

#嵌套列表
x = [[1,2,3],[4,5,6]]
print(x[0])
print(x[0][1])

#内置函数
len(x)
max(x)#取列表中的最大值
min(x)
#类型转换
str1 = "abc"
list2 = list(str1)
print(list2)

#排序
item = [2,1,3,5,4]
print(item.sort())
print(item.sort(reverse=True))


#元祖
tup1 = tuple()#空元祖
tup2 = (1,2,3,4)
print(tup2[2])
print(tup2[:2])
#连接
tup3 = (6,7,8)
tup4 = tup2 +  tup3

#不能删除

len(tup3)


#字典
user_info = {"name":"hx","age":19}
print(user_info)
user_info["name2"] = "路飞"
print(user_info)
print(user_info.keys())
print(user_info.values())
dic1 = {"like":"1212"}
#更新
user_info.update(dic1)
print(user_info)


#集合

st1 = set()

#添加
st1.add("lwq")
print(st1)
st1.add("hhh")

#删除
# st1.remove("xx")#如果集合没有会报错
st1.pop()
st1.discard("xx")#如果集合没有 也不会报错

set2 = set({"hh","kk"})
print(set2)





#流程控制  if and 循环

if 10 > 2:
    print("true")
else:
    print("false")

name = "hh"
if name in name_list:
    print("ok")
else:
    print("no")
a = 16
if a < 10:
    print(1)
elif a > 13 :
    print(2)
else :
    print(3)

for name in name_list:
    print(name)

else:
    print("遍历完成")

for i in range(0,10):
    if i > 5:
        break
    elif i == 5 :
        print(i)
        continue
for k in user_info.keys():
    print(k)

for v in user_info.values():
    print(v)

for k,v in user_info.items():
    print(f"{k}:{v}")#格式化字符串



#循环语句
a = 1
while a < 10:
    print(a)
    a+=2

#for循环
str1= "lvq"
for m in str1:
    print(m)
for i in range(len(str1)):
    print(str1[i])

#嵌套循环
item = [[1,2,3],[4,5,6]]
for i in item:
    for j in i:
        print(j)


#迭代器与生成器
#两种方法 iter next

list = [1,2,3,4]
it = iter(list)
# print(it)
print(next(it))#只往前不会往后

for data in it:
    print(data)

list2 = [1,3,5,6]
it = iter(list2)

while True:
    try:
        print(next(it))
    except StopIteration:
        break

#用一个类实现迭代器 而这个类中需要实现两个方法：iter next
class MyNumbers:
    def __iter__(self):
        self.a = 1
        return self
    def __next__(self):
        x = self.a
        self.a += 1
        return x

myclass = MyNumbers()
myiter = iter(myclass)
print(next(myiter))

#yield 生成器
def fibonacci(n):
    a,b = 0,1
    counter = 0
    while True:
        if counter >= n:
            return
        yield a
        a,b = b,a+b
        counter+=1
f = fibonacci(10)
while True:
    try:
        print(next(f))
    except StopIteration:
        break


#输入输出

#格式化字符
"""
str() 
str.format() 

"""

s = "hello kkb"
print(s)
print(str(s))
print(repr(s))

x = 10 * 3.25
y = 200 * 2009

s = "k的值：" + repr(x) + ",y的值：" + repr(y)
print(s)

print("{}网址：{}!".format("kkb","kaikeba.com"))
print("x的值：{}，y的值{}".format(x,y))
print("{1}网址：{0}!".format("kkb","kaikeba.com"))#有了索引 可以调换位置 
print("{name}网址：{id}!".format(id = "kkb",name = "kaikeba.com"))#可以通过关键字